package com.sky.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {

    private int code;//接口状态
    private long count;//数据的数量
    private String msg;//消息提示信息
    private Object data;//数据

    public Result(int code, String msg, Object data){
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
    public Result(int code, String msg){
        this.code = code;
        this.msg = msg;
    }
    /**
     * 普通查询的成功
     * @param data
     * @return
     */
    public static Result success(Object data){
        Result result = new Result();
        result.setCode(0);
        result.setData(data);
        return result;
    }

    /**
     * 带分页查询的成功方法
     * @param pageInfo
     * @return
     */
   /* public static Result success(PageInfo pageInfo){
        Result result = new Result();
        result.setCode(0);
        result.setCount(pageInfo.getTotal());
        result.setMsg("获取成功");
        result.setData(pageInfo.getList());
        return result;
    }*/

    /**
     * 增删改成功
     * @param msg
     * @return
     */
    public static Result success(String msg){
        Result result = new Result();
        result.setMsg(msg);
        result.setCode(0);
        return result;
    }

    /**
     * 失败的情况
     * @param data
     * @return
     */
    public static Result fail(Object data){
        Result result = new Result();
        result.setCode(0);
        result.setData(data);
        return result;
    }
}
